<?php
namespace app\common\model;

use think\Model;

class Category extends Model   //model层 数据添加到数据库
{
     protected $autoWriteTimestamp = 'ture';  //插入数据库的时候时间戳自动添加
	 
	 //添加分类  向数据库插入数据
	 public function add($data){
		 $data['status'] = 1;
		// $tt=time();
		// $data['create_time'] = date("Y-m-d H:i:s",$tt);
		// $data['create_time'] = time();
		return $this->save($data);
		 
		 }
      //添加分类  分类栏目展示一级目录
      public function getNormalFirstCategory(){
		  $data = [
		      'status' => 1,
			  'parent_id' => 0,		  
		  ];
		  $order = [
		      'id' => 'desc',
		  ];
		  return $this -> where($data)
		               ->order($order)
				       ->select();
		  
		  }
		  
		  //分类展示一or二级目录
		  public function getFirstCategorys($parentId = 0){
		  $data = [
		      'status' => ['neq',-1],
			  'parent_id' => $parentId,		  
		  ];
		  $order = [
		      'listorder' => 'desc',
			  'id' => 'desc',
		  ];
		  $result = $this -> where($data)
		               ->order($order)
				       ->paginate(3); //分页
					   //  echo $this->getLastSql();
		  return $result;
		  }
		  
		  
 public function getNormalCategorysByParentId($parentId = 0){
		 $data = [
		      'status' => 1,
			  'parent_id' => $parentId,		  
		  ];
		  $order = [
		      'id' => 'desc',
		  ];
		  return $this -> where($data)
		               ->order($order)
				       ->select();
		
		}


 public function getNormalRecommendCategoryByParentId($id=0, $limit=5){
	  $data=[
	      'parent_id' => $id,
	      'status' =>1,
	  ];
	  $order=[
	      'listorder' => 'desc',
	      'id' => 'desc',
	  ];
	 $result = $this->where($data)->order($order);
	 if($limit){
		 $result = $result->limit($limit);
		 }
	 return $result->select();
	 }


 public function getNormalRecommendCategoryIdByParentId($ids){
	 $data=[
	      'parent_id' => ['in', implode(',', $ids)],
	      'status' =>1,
	  ];
	  $order=[
	      'listorder' => 'desc',
	      'id' => 'desc',
	  ];
	 $result = $this->where($data)->order($order)->select();

	 return $result;
	 
	 
	 }








}